package bstsetcode;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/13 18:46
 */
public class SelectionSortT {

    public SelectionSortT() {
    }

    /**
     * extends在类上表示继承
     * extends在泛型中使用表示实现某个接口，比如<E extends Comparable<E>
     *
     * @param <E>
     * @param data
     */
    public static <E extends Comparable<E> > void sort(E[] data){

        for (int i = 0; i < data.length; i++) {
            int minIndex = i;
            for (int j = i; j < data.length; j++) { // 从i开始
                if(data[j].compareTo(data[minIndex]) < 0){
                    minIndex = j;
                }
            }
            exchange(data,i,minIndex);

        }

    }

    private static <E> void exchange(E[] data, int i, int j) {
        E temp = data[i];
        data[i] =data[j];
        data[j] = temp;
    }



    public static void main(String[] args) {
        Integer[] data2 = {6,4,2,3,2,1,5,5,};
        SelectionSortT.sort(data2);
        for (int n:data2){
            System.out.print(n +" ");
        }
        System.out.println();

         Student[] students = {
                 new Student("faker", 99),
                 new Student("bang", 90),
                 new Student("bengi", 99)
         };
         SelectionSortT.sort(students);
         for (Student student:students){
             System.out.print(student+" ");
         }
        System.out.println();


    }


}
